package org.splink.deepsplink.page.request {
	import org.splink.deepsplink.page.operation.IPageOperation;
	import org.splink.library.distributor.Dtype;
	import org.splink.library.distributor.IDevent;
	import org.splink.library.distributor.IDistributor;
	import org.splink.library.queue.IQable;

	/**
	 * Decorates an <code>IPageOperation</code> implementation
	 * to provide the means to sort the operation by layer, pageId 
	 * and isOverlay value.
	 * 
	 * @author Max Kugland
	 */
	final internal class SortableOperationDecorator implements IPageOperation {
		private var _proxy : IQable;
		
		/**
		 * public fields for sorting 
		 */
		public var pageId : String;
		public var layer : int;
		public var isOverlay : Boolean;
		
		/**
		 * @param proxy the proxy to be decorated
		 * @param pageId the id of the page		 * @param layer the layer of the page within the page tree		 * @param isOverlay whether the page of the decorated proxy is an overlay page
		 */
		public function SortableOperationDecorator(proxy : IQable, pageId : String, layer : int, isOverlay : Boolean) {
			_proxy = proxy;
			this.pageId = pageId;
			this.layer = layer;
			this.isOverlay = isOverlay;
		}
		
		/**
		 * @inheritDoc
		 */
		public function get id() : String {
			return _proxy.id;
		}
		
		/**
		 * @inheritDoc
		 */
		public function stop() : void {
			_proxy.stop();
		}
		
		/**
		 * @inheritDoc
		 */
		public function start() : void {
			_proxy.start();
		}
		
		/**
		 * @inheritDoc
		 */
		public function reset() : void {
			_proxy.reset();
		}
		
		/**
		 * @inheritDoc
		 */
		public function distribute(event : IDevent) : void {
			_proxy.distribute(event);
		}
		
		/**
		 * @inheritDoc
		 */
		public function register(type : Dtype, fnc : Function, params : Object = null, priority : uint = uint.MIN_VALUE) : IDistributor {
			return _proxy.register(type, fnc, params, priority);
		}
		
		/**
		 * @inheritDoc
		 */
		public function unregister(type : Dtype, fnc : Function) : IDistributor {
			return _proxy.unregister(type, fnc);
		}
		
		/**
		 * @inheritDoc
		 */
		public function finalize() : void {
			_proxy.finalize();
			_proxy = null;
		}
	}
}